package com.example.serialportdemo;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.serialportdemo.service.SerialPortService;

public class TestActivity extends AppCompatActivity {
    private Button cool_1,cool_2;
    private IMyAidlInterface myAidlInterface2=new IMyAidlInterface.Default();
    ServiceConnection connection2=new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            myAidlInterface2=IMyAidlInterface.Stub.asInterface(service);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        bindService(new Intent(TestActivity.this, SerialPortService.class),connection2,BIND_AUTO_CREATE);
        cool_1=findViewById(R.id.btn_cool_1);
        cool_2=findViewById(R.id.btn_cool_2);
        cool_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if(myAidlInterface2.switchTestMode_1()){
                        Toast.makeText(TestActivity.this, "制冷系统1", Toast.LENGTH_SHORT).show();
                    }
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        });
        cool_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if(myAidlInterface2.switchTestMode_2()){
                        Toast.makeText(TestActivity.this, "制冷系统2", Toast.LENGTH_SHORT).show();
                    }
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}